package com.itheima.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.SmsCouponProductRelationMapper;
import com.itheima.pojo.SmsCouponProductRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsCouponProductRelationApiImpl implements SmsCouponProductRelationApi{
    @Autowired
    private SmsCouponProductRelationMapper smsCouponProductRelationMapper;
    /**
     * 优惠券绑定的商品添加
     * @param productRelationList
     */
    @Override
    public void create(List<SmsCouponProductRelation> productRelationList) {
        for (SmsCouponProductRelation smsCouponProductRelation : productRelationList) {
            smsCouponProductRelationMapper.insert(smsCouponProductRelation);
        }
    }

    /**
     * 根据couponId删除优惠券关联信息
     * @param couponId
     */
    @Override
    public void deleteByCouponId(Integer couponId) {
        LambdaQueryWrapper<SmsCouponProductRelation> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(SmsCouponProductRelation::getCouponId,couponId);
        smsCouponProductRelationMapper.delete(wrapper);
    }

    /**
     * 修改
     * @param smsCouponProductRelation
     */
    @Override
    public void updateById(SmsCouponProductRelation smsCouponProductRelation) {
        smsCouponProductRelationMapper.updateById(smsCouponProductRelation);
    }

    /**
     * 获取单个优惠券信息
     * @param couponId
     * @return
     */
    @Override
    public List<SmsCouponProductRelation> getSmsCouponById(Integer couponId) {
        LambdaQueryWrapper<SmsCouponProductRelation> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(SmsCouponProductRelation::getCouponId,couponId);
        return smsCouponProductRelationMapper.selectList(wrapper);
    }
}
